<%@page import="models.config.SiteConfigModel"%>
<%@page import="helpers.DateHelper"%>
<%@page import="java.util.List"%>
<%@page import="models.OwnerDomainModel"%>
<%@page import="models.UserModel"%>
<%@page import="java.util.TreeMap"%>
<%@page import="helpers.UrlHelper"%>
<%@page import="java.util.ArrayList"%>
<%
	TreeMap check = (TreeMap) request.getAttribute("check");
	String success = (String) request.getAttribute("success");
	SiteConfigModel siteConfig = (SiteConfigModel) request.getAttribute("config");
	String image = UrlHelper.getServerUrl(request) + "/blobstore-serve?blob-key=" + siteConfig.getLogo();
	String form = (String) request.getAttribute("form");
	ArrayList<OwnerDomainModel> vertifyDomain = (ArrayList<OwnerDomainModel>) request.getAttribute("vertifyDomain");
	ArrayList<OwnerDomainModel> unvertifyDomain = (ArrayList<OwnerDomainModel>) request.getAttribute("unvertifyDomain");
	String yoursite = (String) request.getAttribute("yoursite");
	UserModel user = (UserModel) request.getAttribute("user");
%>


<jsp:include page="/layouts/demo/header.jsp">
    <jsp:param name="title" value="<%=siteConfig.getTitle()%>" />
    <jsp:param name="description" value="<%=siteConfig.getMetaDescription()%>" />
    <jsp:param name="keywords" value="<%=siteConfig.getMetaKeywords()%>" />
    <jsp:param name="ogsite_name" value="<%=siteConfig.getSiteName()%>" />
    <jsp:param name="ogtitle" value="<%=siteConfig.getTitle()%>" />
    <jsp:param name="ogurl" value="<%=UrlHelper.getServerUrl(request)%>" />
    <jsp:param name="ogimage" value="<%=image %>" />
    <jsp:param name="ogdescription" value="<%=siteConfig.getMetaDescription()%>" />
</jsp:include>

		<div class="dir">
			<a href="/home">Home</a> >  Owner Site
		</div>
		<br />
		<div class="submit-form">
			<form action="" method="post">
			<table width="100%" cellpadding="0" cellspacing="0">
				<thead>
					<tr>
						<td colspan="4">
							<div class="title-form">Your site vertify</div>
							<% if (user.getSessionToken() == null || user.getSessionToken().isEmpty()) { %>
							<a href="/authorization-analytics?action=authorize">Authorize with Google Analytics</a>
							<% } else { %>
							<p>You have authorized this application to access your Google Analytics account.
        						<a href="/authorization-analytics?action=revoke">Revoke access</a>
      						</p>
      						<% } %>
						</td>
					</tr>
				</thead>
				<tbody>
					<tr class="dotline">
						<td align="center">Website</td>
						<td align="center">Website Status</td>
						<td align="center">Username</td>
						<td align="center">Update</td>
					</tr>
					<%
						for (int i = 0; i < vertifyDomain.size(); i++) {
					%>
					<tr class="border-bottom">
						<td width="30%" class="domain">
							<%=vertifyDomain.get(i).getDomain() %>
							<br />
							<span style="font-size: 12px; color: #444;">
								<% if (vertifyDomain.get(i).getAnalyticProfileId() != null && !vertifyDomain.get(i).getAnalyticProfileId().isEmpty()
										&& user.getSessionToken() != null && !user.getSessionToken().isEmpty()) { %>
								<a href="/analytic/info?api=<%=vertifyDomain.get(i).getAnalyticProfileId()%>&domain=<%=vertifyDomain.get(i).getDomain() %>">Get Analytics data</a><br />
								Get data from analytics account <br /><br />
								<% } %>
	                            <a href="/profile/edit/title?domain=<%=vertifyDomain.get(i).getDomain() %>">Click to edit site profile title</a><br>
	                            Most important page heading for search engine optimization also known as H1<br><br>
	                            <a href="/profile/edit/description?domain=<%=vertifyDomain.get(i).getDomain() %>">Click to edit owner description</a><br>
	                            Tell our users about your website. What is your niche? How is it useful for visitors? You can use up to 4 links in website description.<br><br>
	                            <a href="/profile/delete?domain=<%=vertifyDomain.get(i).getDomain() %>">Delete owner site</a>
                            </span>
						</td>
						<td>
							<a href="/profile/edit/status?domain=<%=vertifyDomain.get(i).getDomain() %>"><%=vertifyDomain.get(i).getActive() == 1 ? "Active" : "Hidden" %></a>
						</td>
						<td>
							<%=vertifyDomain.get(i).getUsername() %>
						</td>
						<td align="center">
							<% 
								if (vertifyDomain.get(i).getIsUpdated() == 0) {
									List<Long> d = DateHelper.coundownFromNow(vertifyDomain.get(i).getLastUpdate());
							%>
								<span>We will review and confirm your content change soon, or this domain will auto next update after:<br /> 
									<strong><%=d.get(0) > 0 ? Long.toString(d.get(0)) : "0" %></strong> days, 
									<strong><%=d.get(1) > 0 ? Long.toString(d.get(1)) : "0" %></strong> hours, 
									<strong><%=d.get(2) > 0 ? Long.toString(d.get(2)) : "0"%></strong> minutes
								</span>
								
								<br />
								<a href="/preview/<%=vertifyDomain.get(i).getDomain()%>">Preview</a>
							<% 
								} else {
									List<Long> l = DateHelper.calDistanceTimeToNow(vertifyDomain.get(i).getLastUpdate());
							%>
								<span>Last updated: <br />
									<strong><%=l.get(0) > 0 ? Long.toString(l.get(0)) : "0" %></strong> days, 
									<strong><%=l.get(1) > 0 ? Long.toString(l.get(1)) : "0" %></strong> hours, 
									<strong><%=l.get(2) > 0 ? Long.toString(l.get(2)) : "0"%></strong> minutes
								</span>
							<% } %>
						</td>
					</tr>
					<% } %>
				</tbody>
			</table>
			<table width="100%" cellpadding="0" cellspacing="0">
				<thead>
					<tr>
						<td colspan="2"><div class="title-form">Your site unvertify</div></td>
					</tr>
				</thead>
				<tbody>
					<%
						for (int i = 0; i < unvertifyDomain.size(); i++) {
					%>
					<tr>
						<td width="30%" class="domain"><a href="/profile/verify?domain=<%=unvertifyDomain.get(i).getDomain()%>"><%=unvertifyDomain.get(i).getDomain() %></a></td>
						<td>
							<%=unvertifyDomain.get(i).getUsername() %> &nbsp; (<a href="/profile/delete?id=<%=unvertifyDomain.get(i).getId()%>">Remove site</a>)
						</td>
					</tr>
					<% } %>
				</tbody>
			</table>
			<table width="100%" cellpadding="0" cellspacing="0">
				<thead>
					<tr>
						<td colspan="2"><div class="title-form">Add your website</div></td>
					</tr>
				</thead>
				<tbody>
					<tr>
						<td width="30%" class="domain">Your site</td>
						<td>
							<% if (check.get("yoursite") != null) { %>
								<div class="error"><%=check.get("yoursite")%></div>
							<% } %>
							<input type="text" name="yoursite" value="<%=yoursite == null ? "http://" : "http://" + yoursite %>" />
						</td>
					</tr>
					<tr>
						<td></td>
						<td>
							<button type="submit">Next >></button>
						</td>
					</tr>
				</tbody>
			</table>
			</form>
		</div>
<jsp:include page="/layouts/demo/footer.jsp">
    <jsp:param name="language" value="1" />
</jsp:include>